home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
BSFINFO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-24
|
8KB
|
295 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: bsfinfo.c
// Title: Base library
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
//
// This module contains to query and set file information.
//
// The code in this module should be written entirely in C.
// Do not use any C++ constructs.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
// SCO UNIX.
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
// SCO UNIX cc
//
//----------------------------------------------------------------------------
#include <bs.h>
//----------------------------------------------------------------------------
// Description: Close find first/next operation and free data
// Parameters: pv Find first/next data structure
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E FinfoFindClose(PVOID pv)
{
if (pv) // Free data structure
MemFree(pv);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Convert between find first/next and file info structure
// Parameters: pv Find first/next data structure
// pfinfo File info structure
// Returns:
//----------------------------------------------------------------------------
#if OS_UNIX==0
static VOID FN_L FinfoFindConvert(PVOID pv, PBS_FINFO pfinfo)
{
struct find_t *fffn = (struct find_t *)pv;
struct tm tm_file;
if (!pfinfo)
return ;
memset(pfinfo, 0, sizeof(BS_FINFO));
strcpy(pfinfo->szFname, fffn->name);
pfinfo->usAttrib = (USHORT)fffn->attrib;
pfinfo->lSize = (LONG)fffn->size;
memset(&tm_file, 0, sizeof(tm_file));
tm_file.tm_sec = (fffn->wr_time & 0x001F) * 2;
tm_file.tm_min = ((fffn->wr_time >> 5) & 0x003F);
tm_file.tm_hour = ((fffn->wr_time >> 11) & 0x001F);
tm_file.tm_mday = (fffn->wr_date & 0x001F);
tm_file.tm_mon = ((fffn->wr_date >> 5) & 0x000F) - 1;
tm_file.tm_year = ((fffn->wr_date >> 9) & 0x007F) + 80;
pfinfo->timet = mktime(&tm_file);
return ;
}
#endif
//----------------------------------------------------------------------------
// Description: Find first file.
// Parameters: pcsz File specification
// usAttrib File attribute mask
// pfinfo File information structure
// Returns: Pointer to find first/next data structure or NULL.
//----------------------------------------------------------------------------
PVOID FN_E FinfoFindFirst(PCSZ pcsz, USHORT usAttrib, PBS_FINFO pfinfo)
{
#if OS_UNIX
NOTUSED(pcsz);
NOTUSED(usAttrib);
NOTUSED(pfinfo);
return FALSE;
#else
PVOID pv = MemAlloc(sizeof(struct find_t));
CHAR szPath[MAX_PATH];
if (pv == NULL)
return pv;
Assert(pcsz);
FnameNormalize(strcpy(szPath, pcsz), FNAME_DIR);
if (_dos_findfirst(szPath, (int)usAttrib, pv))
{
MemFree(pv);
return NULL;
}
if (pfinfo)
FinfoFindConvert(pv, pfinfo);
return pv;
#endif
}
//----------------------------------------------------------------------------
// Description: Find next file
// Parameters: pv Find first/next structure
// pfinfo File information structure
// Returns: TRUE if file found.
//----------------------------------------------------------------------------
BOOL FN_E FinfoFindNext(PVOID pv, PBS_FINFO pfinfo)
{
#if OS_UNIX
NOTUSED(pv);
NOTUSED(pfinfo);
return FALSE;
#else
Assert(pv);
// finds 2 files, pf.db and cs.db..neither one works.
if (_dos_findnext(pv))
return FALSE;
if (pfinfo)
FinfoFindConvert(pv, pfinfo);
return TRUE;
#endif
}
//----------------------------------------------------------------------------
// Description: Get file information
// Parameters: pcsz File name
// pfinfo File information
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E FinfoGet(PCSZ pcsz, PBS_FINFO pfinfo)
{
#if OS_UNIX
NOTUSED(pcsz);
Assert(pcsz && pfinfo);
memset(pfinfo, 0, sizeof(BS_FINFO));
return TRUE;
#else
struct find_t fffn;
CHAR szPath[MAX_PATH];
Assert(pcsz && pfinfo);
FnameFullPath(strcpy(szPath, pcsz));
if (_dos_findfirst(szPath, FA_ARCHIVE|FA_READONLY|FA_SYSTEM|FA_HIDDEN, &fffn))
return Error("File not found.\n'%s'", szPath);
FinfoFindConvert((PVOID)&fffn, pfinfo);
return TRUE;
#endif
}
//----------------------------------------------------------------------------
// Description: Set file information
// Parameters: pcsz File name
// pfinfo File information
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_E FinfoSet(PCSZ pcsz, PBS_FINFO pfinfo)
{
#if OS_UNIX
NOTUSED(pcsz);
NOTUSED(pfinfo);
return TRUE;
#else
USHORT usAttrib;
USHORT usDate;
USHORT usTime;
struct tm *tm;
HF hf;
CHAR szPath[MAX_PATH];
Assert(pcsz && pfinfo);
FnameFullPath(strcpy(szPath, pcsz));
tm = localtime(&pfinfo->timet);
usDate = (USHORT)((tm->tm_mday & 0x001F)
+ (((tm->tm_mon + 1) & 0x000F) << 5)
+ (((tm->tm_year - 80) & 0x007F) << 9));
usTime = (USHORT)(((tm->tm_sec / 2) & 0x001F)
+ ((tm->tm_min & 0x003F) << 5)
+ ((tm->tm_hour & 0x001F) << 11));
if (_dos_getfileattr(szPath, (unsigned *)&usAttrib))
return Error("Could not get file attributes.");
usAttrib &= ~(_A_RDONLY|_A_HIDDEN|_A_SYSTEM);
if (_dos_setfileattr(szPath, usAttrib))
return Error("Could not set file attributes.");
if (!FileOpen(&hf, szPath, FL_OPEN|FL_READWRITE|FL_DENYWRITE|FL_BINARY, NULL))
return FALSE;
if (_dos_setftime(hf, usDate, usTime))
{
FileClose(hf);
return Error("Could not set file attributes.");
}
if (!FileClose(hf))
return FALSE;
if (_dos_setfileattr(szPath, pfinfo->usAttrib))
return Error("Could not set file attributes.");
return TRUE;
#endif
}
//----------------------------------------------------------------------------
// Description: Run standard test suite
// Parameters: sTest Test to run.
// 0 Run all default tests (except).
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_TEST
BOOL FN FinfoTest(SHORT sTest)
{
BS_FINFO finfo;
PVOID pv;
struct tm *tm;
NOTUSED(sTest);
pv = FinfoFindFirst("*.*", 0, &finfo);
if (pv)
{
do
{
tm = localtime(&finfo.timet);
Output("%-16.16s %9ld %04X %2d:%02d:%02d %2d/%02d/%4d\n",
finfo.szFname,
finfo.lSize,
finfo.usAttrib,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
}
while (FinfoFindNext(pv, &finfo));
FinfoFindClose(pv);
}
if (!FinfoGet("bsfinfo.c", &finfo))
return FALSE;
tm = localtime(&finfo.timet);
Output("%-16.16s %9ld %04X %2d:%02d:%02d %2d/%02d/%4d\n",
finfo.szFname,
finfo.lSize,
finfo.usAttrib,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
finfo.usAttrib &= ~FA_ARCHIVE;
finfo.timet--;
if (!FinfoSet("bsfinfo.c", &finfo))
return FALSE;
if (!FinfoGet("bsfinfo.c", &finfo))
return FALSE;
tm = localtime(&finfo.timet);
Output("%-16.16s %9ld %04X %2d:%02d:%02d %2d/%02d/%4d\n",
finfo.szFname,
finfo.lSize,
finfo.usAttrib,
tm->tm_hour, tm->tm_min, tm->tm_sec,
tm->tm_mon + 1, tm->tm_mday, tm->tm_year + 1900);
return TRUE;
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------